-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: mark untagged manifests as garbage during GC and delete #680
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #680 +/- ##
==========================================
+ Coverage 75.78% 75.85% +0.07%
==========================================
Files 59 59
Lines 5769 5873 +104
==========================================
+ Hits 4372 4455 +83
- Misses 1026 1040 +14
- Partials 371 378 +7 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a minor suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi!
Thank you for this PR!
As advised in #664, I tested this PR in a branch:
francis@pwmachine:~/Codes/kinvolk/inspektor-gadget$ sudo -E ./ig image build -t opens -f gadgets/trace_open/gadget.yaml gadgets/trace_open
INFO[0000] Experimental features enabled
Successfully built ghcr.io/inspektor-gadget/gadget/opens:latest@sha256:a5de3655d6c7640eb6d43f7d9d7182b233ac86aedddfe6c132cba6b876264d97
francis@pwmachine:~/Codes/kinvolk/inspektor-gadget$ sudo cat /var/lib/ig/oci-store/index.json | jq francis/rmi-upstream % u=
{
"schemaVersion": 2,
"manifests": [
{
"mediaType": "application/vnd.oci.image.index.v1+json",
"digest": "sha256:a5de3655d6c7640eb6d43f7d9d7182b233ac86aedddfe6c132cba6b876264d97",
"size": 491,
"annotations": {
"org.opencontainers.image.ref.name": "ghcr.io/inspektor-gadget/gadget/opens:latest"
}
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:6fc908439cd210687651e36693d4fa96e59259403826c7cf929ac5382c8d6a33",
"size": 582,
"platform": {
"architecture": "amd64",
"os": "linux"
}
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:b4c03573365a929cbde0bf6e92ed91e067647501851a6d84a6f2a1a072bf22ce",
"size": 582,
"platform": {
"architecture": "arm64",
"os": "linux"
}
}
]
}
francis@pwmachine:~/Codes/kinvolk/inspektor-gadget$ sudo -E ./ig image remove opens francis/rmi-upstream % u=
INFO[0000] Experimental features enabled
Successfully removed opens
francis@pwmachine:~/Codes/kinvolk/inspektor-gadget$ sudo cat /var/lib/ig/oci-store/index.json | jq francis/rmi-upstream % u=
{
"schemaVersion": 2,
"manifests": [
{
"mediaType": "application/vnd.oci.image.index.v1+json",
"digest": "sha256:a5de3655d6c7640eb6d43f7d9d7182b233ac86aedddfe6c132cba6b876264d97",
"size": 491
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:6fc908439cd210687651e36693d4fa96e59259403826c7cf929ac5382c8d6a33",
"size": 582,
"platform": {
"architecture": "amd64",
"os": "linux"
}
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:b4c03573365a929cbde0bf6e92ed91e067647501851a6d84a6f2a1a072bf22ce",
"size": 582,
"platform": {
"architecture": "arm64",
"os": "linux"
}
}
]
}
As a result, the tag was just removed from the index but nothing no blobs were actually removed.
Am I missing something?
With regard to the code itself, I found two nits.
Best regards.
Hi @eiffel-fl, If I understand your scenario correctly, when you delete an image index, you also want the manifests in the index to be automatically removed, given that the manifests are untagged and do not have other tagged predecessors. I have added a simple unit test to cover the scenario of deleting an image index. It looks like it's working as expected. In this unit test, untagged manifests are all removed and the tagged one remains. I see that in your branch, you replaced |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi!
I see that in your branch, you replaced deleteTree (which deletes all successors of root if they have no other predecessors?) with Delete and GC. Logically it should work. Do the manifests have no other tagged predecessors, other than the image index?
I took another look and something is wrong in my code, we modified it recently and I guess the modification had a side effect.
So, I tested the Delete(); GC()
snippet only and got what I expected:
$ sudo -E ./ig image build -t opens -f gadgets/trace_open/gadget.yaml gadgets/trace_open
INFO[0000] Experimental features enabled
Successfully built ghcr.io/inspektor-gadget/gadget/opens:latest@sha256:a5de3655d6c7640eb6d43f7d9d7182b233ac86aedddfe6c132cba6b876264d97
$ sudo ls /var/lib/ig/oci-store/blobs/sha256 francis/rmi-upstream *% u=
35166e636330705738ad3cb162b38aeffe639b718caaee63efe777f510bd2869 a5de3655d6c7640eb6d43f7d9d7182b233ac86aedddfe6c132cba6b876264d97
6fc908439cd210687651e36693d4fa96e59259403826c7cf929ac5382c8d6a33 b4c03573365a929cbde0bf6e92ed91e067647501851a6d84a6f2a1a072bf22ce
a1b5ae61c307cb52fb0480a1bc9b422ef05d1c0e80c9688d65db6cf4e9e7cb31 f10d65e6c0eadaf823f57a5733c9f2bdc444f4c8e4ec77452ba2cfd2c5e258f4
$ sudo cat /var/lib/ig/oci-store/index.json | jq francis/rmi-upstream *% u=
{
"schemaVersion": 2,
"manifests": [
{
"mediaType": "application/vnd.oci.image.index.v1+json",
"digest": "sha256:a5de3655d6c7640eb6d43f7d9d7182b233ac86aedddfe6c132cba6b876264d97",
"size": 491,
"annotations": {
"org.opencontainers.image.ref.name": "ghcr.io/inspektor-gadget/gadget/opens:latest"
}
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:6fc908439cd210687651e36693d4fa96e59259403826c7cf929ac5382c8d6a33",
"size": 582,
"platform": {
"architecture": "amd64",
"os": "linux"
}
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:b4c03573365a929cbde0bf6e92ed91e067647501851a6d84a6f2a1a072bf22ce",
"size": 582,
"platform": {
"architecture": "arm64",
"os": "linux"
}
}
]
}
$ sudo -E ./ig image list francis/rmi-upstream *% u=
INFO[0000] Experimental features enabled
REPOSITORY TAG DIGEST
opens latest a5de3655d6c7
$ sudo -E ./ig image remove opens francis/rmi-upstream *% u=
INFO[0000] Experimental features enabled
Successfully removed opens
$ sudo cat /var/lib/ig/oci-store/index.json | jq francis/rmi-upstream *% u=
{
"schemaVersion": 2,
"manifests": null
}
$ sudo ls /var/lib/ig/oci-store/blobs/sha256 francis/rmi-upstream *% u=
$ git diff
diff --git a/go.mod b/go.mod
index 1d5560ba..0a6efeae 100644
--- a/go.mod
+++ b/go.mod
@@ -49,7 +49,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1
github.com/kr/pretty v0.3.1
github.com/moby/moby v24.0.7+incompatible
- github.com/opencontainers/image-spec v1.1.0-rc5
+ github.com/opencontainers/image-spec v1.1.0-rc6
github.com/prometheus/client_golang v1.18.0
github.com/shopspring/decimal v1.3.1
github.com/spf13/viper v1.18.2
@@ -204,4 +204,4 @@ replace sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.13.1
replace github.com/vishvananda/netns => github.com/inspektor-gadget/netns v0.0.5-0.20230524185006-155d84c555d6
-replace oras.land/oras-go/v2 => github.com/wangxiaoxuan273/oras-go/v2 v2.0.0-20240119103641-f8911ebadde6
+replace oras.land/oras-go/v2 => github.com/wangxiaoxuan273/oras-go/v2 v2.0.0-20240123071211-5650fa5bbcc2
So, thank you a lot for the code!
Best regards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
following #680 and addressing this comment: #680 (comment) Signed-off-by: Xiaoxuan Wang <[email protected]>
Related to #664